<!--查询所有专家-->
<template>
    <div>
        <div class="allExpert-page">
            <expert-source :cexpertArray="expertArray" @handleSearch="handleSearch" @refresh="refresh"></expert-source>
            <!-- 分页 -->
            <div v-show="null !== expertArray && expertArray.length > 0"
                style="width: 100%;display:flex;justify-content: center;margin-top: 10px;">
                <el-pagination layout="prev,pager,next" :page-size="pageSize" :total="total"
                    @current-change="handleCurrentChange" />
            </div>
        </div>
    </div>
</template>

<script setup>
import { selectExpert } from "@/api/order";
import store from '@/store'
import { ref } from 'vue'
import ExpertSource from "@/components/ExpertSource.vue";
import { useRouter } from 'vue-router';

const router = useRouter()
const total = ref(0)
const pageSize = ref(4)
const expertArray = ref([])
const searchKeys = ref('')

// 获取数据
const load = () => {
    selectExpert({
        pageNum: 1,
        pageSize: pageSize.value
    }).then(res => {
        if (res.flag == true) {
            expertArray.value = res.data.data
            total.value = res.data.total
        }
    })
    searchKeys.value = ''
}
load()

//搜索
const handleSearch = (val) => {
    searchKeys.value = val
    selectExpert({
        pageNum: 1,
        pageSize: pageSize.value,
        keys: searchKeys.value
    }).then(res => {
        if (res.flag == true) {
            expertArray.value = res.data.data
            total.value = res.data.total
        }
    })
}

//专家数据分页
const handleCurrentChange = (val) => {
    if (searchKeys.value == '') {
        selectExpert({
            pageNum: val,
            pageSize: pageSize.value
        }).then(res => {
            if (res.flag == true) {
                expertArray.value = res.data.data
            }
        })
    }
    else if (searchKeys.value != '') {
        selectExpert({
            pageNum: val,
            pageSize: pageSize.value,
            keys: searchKeys.value
        }).then(res => {
            if (res.flag == true) {
                expertArray.value = res.data.data
            }
        })
    }
}

//刷新
const refresh = () => {
    load()
    searchKeys.value = ''
}


</script>

<style lang="scss" scoped>
.allExpert-page {
    width: 100%;
    margin: 0 auto;
    // float: left;
}
</style>